package com.lz.redis.common.enums;

import com.lz.redis.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 环境模式枚举
 */
@Getter
@AllArgsConstructor
public enum EnvMode {

    GJ("国君"),
    HY("宏源");

    private final String desc;

    /**
     * code to enum mapping
     */
    static final Map<String, EnvMode> ENTRY = new HashMap<>();

    static {
        for (EnvMode payDirection : EnvMode.values()) {
            ENTRY.put(payDirection.name(), payDirection);
        }
    }

    /**
     * 根据code获取枚举类型
     */
    public static EnvMode valueOfName(String name) {
        EnvMode envMode = ENTRY.get(name);
        if (envMode == null) {
            throw new ServiceException(String.format("No enum name '%s' in %s", name, EnvMode.class));
        }
        return envMode;
    }
}
